package com.alipay.traditionalbus;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by crazytime on 14-3-1.
 */
public class EventConsumer implements Runnable {

    private AtomicBoolean stopFlag;
    private EventBus bus;
    private CountDownLatch consume;

    public EventConsumer(EventBus bus,AtomicBoolean stopFlag,CountDownLatch consume){
        this.bus=bus;
        this.stopFlag=stopFlag;
        this.consume=consume;
    }


    @Override
    public void run() {
        while (true){
            if(stopFlag.get() && bus.isEmpty())
                break;
            if(bus.isEmpty()){
                continue;
            }else{
                bus.getEvent();
            }
        }
        consume.countDown();
    }
}
